package com.lightMS.agenda;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.lightMS.agenda.be.Event;
import com.lightMS.agenda.util.Constants;


public class EventAdapter extends ArrayAdapter<Event> {
	
	private final List<Event> list;
	private final Activity context;
	
	public EventAdapter(Activity context, List<Event> list) {
		super(context, R.layout.event_list_item_view, list);
		this.context = context;
		this.list = list;
	}
	
	
	@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;

        if (v == null) {
            LayoutInflater vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.event_list_item_view, null);
        }

        Event item = list.get(position);
        
        if (item != null) {             
        	TextView txtName = (TextView)v.findViewById(R.id.eventNameTextView);
        	Typeface font = Typeface.createFromAsset(context.getAssets(), Constants.EVENT_ITEM_FONT);  
        	txtName.setTypeface(font);
        	txtName.setText(item.getName());
    	}

        return v;
    }
}